<template>
    <basic-container>
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="Idm配置" name="Idm">
                <div style="width:50%;margin-top: 10px;">
                    <avue-form ref="form" v-model="Idm" :option="optionIdm" @submit="submitIdm">
                    </avue-form>
                </div>
            </el-tab-pane>
            <el-tab-pane label="归心配置" name="Gx">
                <div style="width:50%;margin-top: 10px;">
                    <avue-form ref="form" v-model="Gx" :option="optionGx" @submit="submitGx">
                    </avue-form>
                </div>
            </el-tab-pane>
            <el-tab-pane label="Esb配置" name="Esb">
                <div style="width:50%;margin-top: 10px;">
                    <avue-form ref="form" v-model="Esb" :option="optionEsb" @submit="submitEsb">
                    </avue-form>
                </div>
            </el-tab-pane>
            <el-tab-pane label="Bpm配置" name="Bpm">
                <div style="width:50%;margin-top: 10px;">
                    <avue-form ref="form" v-model="Bpm" :option="optionBpm" @submit="submitBpm">
                    </avue-form>
                </div>
            </el-tab-pane>
        </el-tabs>
    </basic-container>
</template>

<script>
    import {
        getIdm,
        setIdm
    } from "../../api/base/sysSet/idmSet";
    import {
        getGx,
        setGx,
    } from "../../api/base/sysSet/gxSet";
    import {
        getEsb,
        setEsb,
        getBpm,
        setBpm,
    } from "../../api/base/sysSet/esbSet";
    import {
        convertAddCode
    } from '@/util/util';

    export default {
        data() {
            return {
                activeName: 'Idm',
                Idm: {},
                Gx: {},
                Esb: {},
                Bpm: {},
                optionIdm: {
                    emptyBtn: false,
                    labelWidth: '200',
                    labelPosition: 'left',
                    column: [{
                        label: "访问idm接口的用户名",
                        prop: "idmInterfaceAccount",
                        tip: 'idm接口用户名',
                        span: 24,
                        rules: [{
                            required: true,
                            message: "请输入idm接口用户名",
                            trigger: "blur"
                        }]
                    }, {
                        label: "访问idm接口的密码",
                        prop: "idmInterfacePassword",
                        tip: 'idm接口密码',
                        span: 24,
                        rules: [{
                            required: true,
                            message: "请输入idm接口密码",
                            trigger: "blur"
                        }]
                    }, {
                        label: " 访问的idm系统标识——获取人员信息的系统标识",
                        prop: "idmGetUserSystemId",
                        tip: 'idm系统标识',
                        span: 24,
                        rules: [{
                            required: true,
                            message: "请输入idm系统标识",
                            trigger: "blur"
                        }]

                    }
                        , {
                            label: "访问的idm系统标识——获取人员信息的系统标识",
                            prop: "idmGetOrgSystemId",
                            tip: 'idm系统标识',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入idm系统标识",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "获取idm授权登录code的url",
                            prop: "idmGetAutho2CodeUrl",
                            tip: 'idm授权登录code的url',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入idm授权登录code的url",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "获取idm授权登录的clientId",
                            prop: "idmClientId",
                            tip: 'idm授权登录的clientId',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入idm授权登录的clientId",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "获取idm授权登录的client_secret",
                            prop: "idmClientSecret",
                            tip: 'idm授权登录的client_secret',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入获取idm授权登录的client_secret",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "获取idm授权登录的回调url",
                            prop: "idmAutho2CodeBackUrl",
                            tip: 'idm授权登录的回调url',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入获取idm授权登录的回调url",
                                trigger: "blur"
                            }]

                        }, {
                            label: "获取idm授权登录的token",
                            prop: "idmAutho2TokenByCode",
                            tip: 'idm授权登录的token',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入idm授权登录的token",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "获取用户信息根据idm授权登录的token",
                            prop: "idmGetUserByToken",
                            tip: '用户信息根据idm授权登录的token',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入用户信息根据idm授权登录的token",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "idm单点退出url及参数",
                            prop: "idmLogoutUrl",
                            tip: 'idm单点退出url及参数',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入idm单点退出url及参数",
                                trigger: "blur"
                            }]

                        }
                    ]
                },
                optionGx: {
                    emptyBtn: false,
                    labelWidth: '200',
                    labelPosition: 'left',
                    column: [{
                        label: "系统在归心的客户端id",
                        prop: "gxClientId",
                        tip: '归心的客户端id',
                        span: 24,
                        rules: [{
                            required: true,
                            message: "请输入归心的客户端id",
                            trigger: "blur"
                        }]
                    }, {
                        label: "访问归心APP接口的密钥",
                        prop: "gxSecret",
                        tip: '归心APP接口的密钥',
                        span: 24,
                        rules: [{
                            required: true,
                            message: "请输入归心APP接口的密钥",
                            trigger: "blur"
                        }]
                    }, {
                        label: " 系统在归心APP的应用id 获取接口访问权限接口的",
                        prop: "gxAppId",
                        tip: '系统在归心APP的应用id',
                        span: 24,
                        rules: [{
                            required: true,
                            message: "请输入系统在归心APP的应用id",
                            trigger: "blur"
                        }]
                    }
                        , {
                            label: "获取接口访问权限接口的token密匙",
                            prop: "gxTokenSecret",
                            tip: '获取接口访问权限接口的token密匙',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入接口访问权限接口的token密匙",
                                trigger: "blur"
                            }]
                        }
                        , {
                            label: "获取授权登录code地址",
                            prop: "gxAuthLoginCodeUrl",
                            tip: '授权登录code地址',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入授权登录code地址",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "获取授权登录code回调地址",
                            prop: "gxAuthLoginCodeBackUrl",
                            tip: '授权登录code回调地址',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入授权登录code回调地址",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "获取授权登录token地址",
                            prop: "gxAuthLoginTokenUrl",
                            tip: '授权登录token地址',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入授权登录token地址",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "获取访问归心接口需要先获取token的地址",
                            prop: "gxInterfaceTokenUrl",
                            tip: '访问归心接口需要先获取token的地址',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入访问归心接口需要先获取token的地址",
                                trigger: "blur"
                            }]

                        }, {
                            label: "归心接口token的有效时长 两小时 60*60*2L",
                            prop: "gxInterfaceTokenEffectiveDuration",
                            tip: '归心接口token的有效时长 ',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入归心接口token的有效时长 两小时 60*60*2L",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "获取归心用户信息根据token",
                            prop: "gxGetUserByToken",
                            tip: '归心用户信息根据token',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入获取归心用户信息根据token",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "获取归心用户信息根据memberId",
                            prop: "gxGetUserByMemberId",
                            tip: '归心用户信息根据memberId',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入归心用户信息根据memberId",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "查询所有的城市",
                            prop: "gxGetCity",
                            tip: '查询所有的城市',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入查询所有的城市",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "根据城市获取项目信息",
                            prop: "gxGetProjectListByCity",
                            tip: '根据城市获取项目信息',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入城市获取项目信息",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "推送消息到归心APP",
                            prop: "gxPushMessageToApp",
                            tip: '推送消息到归心APP',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入推送消息到归心APP",
                                trigger: "blur"
                            }]
                        }
                    ]
                },
                optionEsb: {
                    emptyBtn: false,
                    labelWidth: '200',
                    labelPosition: 'left',
                    column: [{
                        label: "esb webService接口的域名端口",
                        prop: "esbWebServicePrev",
                        tip: 'webService接口的域名端口',
                        span: 24,
                        rules: [{
                            required: true,
                            message: "请输入webService接口的域名端口",
                            trigger: "blur"
                        }]
                    }, {
                        label: "esb Basic校验用户名",
                        prop: "esbBasicUserName",
                        tip: 'Basic校验用户名',
                        span: 24,
                        rules: [{
                            required: true,
                            message: "请输入Basic校验用户名",
                            trigger: "blur"
                        }]
                    }, {
                        label: "esb Basic校验密码",
                        prop: "esbBasicPassword",
                        tip: 'Basic校验密码',
                        span: 24,
                        rules: [{
                            required: true,
                            message: "请输入Basic校验密码",
                            trigger: "blur"
                        }]

                    }
                        , {
                            label: "esb 分配给商城都系统表示",
                            prop: "esbGiveMallSystemId",
                            tip: '分配给商城都系统表示',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入分配给商城都系统表示",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "esb 分配给bpm的系统标识",
                            prop: "esbGiveBpmSystemId",
                            tip: '分配给bpm的系统标识',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入分配给bpm的系统标识",
                                trigger: "blur"
                            }]
                        }
                    ]
                },
                optionBpm: {
                    emptyBtn: false,
                    labelWidth: '200',
                    labelPosition: 'left',
                    column: [{
                        label: "BPM发起流程地址",
                        prop: "bpmInitiationProcessUrl",
                        tip: 'BPM发起流程地址',
                        span: 24,
                        rules: [{
                            required: true,
                            message: "请输入BPM发起流程地址",
                            trigger: "blur"
                        }]
                    }, {
                        label: "业务系统标识",
                        prop: "bpmBsId",
                        tip: '业务系统标识',
                        span: 24,
                        rules: [{
                            required: true,
                            message: "请输入业务系统标识",
                            trigger: "blur"
                        }]
                    }, {
                        label: "业务单据ID",
                        prop: "bpmBtId",
                        tip: '业务单据ID',
                        span: 24,
                        rules: [{
                            required: true,
                            message: "请输入业务单据ID",
                            trigger: "blur"
                        }]

                    }
                        , {
                            label: "查询BPM组织时，需要的ACCOUNT参数",
                            prop: "bpmOrgAccount",
                            tip: '查询BPM组织时需要的ACCOUNT参数',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入查询BPM组织时需要的ACCOUNT参数",
                                trigger: "blur"
                            }]

                        }
                        , {
                            label: "查询BPM组织时，需要的 PASSWORD参数",
                            prop: "bpmOrgPassrwd",
                            tip: '查询BPM组织时，需要的 PASSWORD参数',
                            span: 24,
                            rules: [{
                                required: true,
                                message: "请输入查询BPM组织时，需要的 PASSWORD参数",
                                trigger: "blur"
                            }]
                        }
                    ]
                },

            }
        },
        //页面初始化
        created() {
            this.getIdmFn()
        },
        methods: {
            getGxFn() {
                getGx().then(res => {
                    console.log(res)
                    if (res.data.code == 200) {
                        this.Gx = res.data.data
                    }
                });
            },
            getIdmFn() {
                getIdm().then(res => {
                    console.log(res)
                    if (res.data.code == 200) {
                        this.Idm = res.data.data
                    }
                })
            },
            getEsbFn(){
                getEsb().then(res =>{
                    console.log(res)
                    if (res.data.code == 200) {
                        this.Esb = res.data.data
                    }
                })
            },
            getBpmFn(){
                getBpm().then(res =>{
                    console.log(res)
                    if (res.data.code == 200) {
                        this.Bpm = res.data.data
                    }
                })
            },
            handleClick(tab, event) {
                console.log('tab',tab.name)
                if(tab.name=='Gx') {
                    this.getGxFn()
                }else if(tab.name=='Idm') {
                    this.getIdmFn()
                }else if(tab.name=='Esb'){
                    this.getEsbFn()
                }else if (tab.name=='Bpm'){
                    this.getBpmFn()
                }
            },
            submitIdm(form, done) {
                let dataA = {
                    idmInterfaceAccount: encodeURIComponent(this.Idm.idmInterfaceAccount),
                    idmInterfacePassword: encodeURIComponent(this.Idm.idmInterfacePassword),
                    idmGetUserSystemId: encodeURIComponent(this.Idm.idmGetUserSystemId),
                    idmGetOrgSystemId: encodeURIComponent(this.Idm.idmGetOrgSystemId),
                    idmGetAutho2CodeUrl: encodeURIComponent(this.Idm.idmGetAutho2CodeUrl),
                    idmClientId: encodeURIComponent(this.Idm.idmClientId),
                    idmClientSecret: encodeURIComponent(this.Idm.idmClientSecret),
                    idmAutho2CodeBackUrl: encodeURIComponent(this.Idm.idmAutho2CodeBackUrl),
                    idmAutho2TokenByCode: encodeURIComponent(this.Idm.idmAutho2TokenByCode),
                    idmGetUserByToken: encodeURIComponent(this.Idm.idmGetUserByToken),
                    idmLogoutUrl: encodeURIComponent(this.Idm.idmLogoutUrl)
                }
                console.log(dataA)
                setIdm(dataA).then(() => {
                    done()
                    this.$message({
                        message: '提交成功',
                        type: 'success'
                    })
                    this.activeName = 'Idm'
                    this.getData()
                })
            },
            submitGx(form, done) {
                let dataB = {
                    gxClientId: encodeURIComponent(this.Gx.gxClientId),
                    gxSecret: encodeURIComponent(this.Gx.gxSecret),
                    gxAppId: encodeURIComponent(this.Gx.gxAppId),
                    gxTokenSecret: encodeURIComponent(this.Gx.gxTokenSecret),
                    gxAuthLoginCodeUrl: encodeURIComponent(this.Gx.gxAuthLoginCodeUrl),
                    gxAuthLoginCodeBackUrl: encodeURIComponent(this.Gx.gxAuthLoginCodeBackUrl),
                    gxAuthLoginTokenUrl: encodeURIComponent(this.Gx.gxAuthLoginTokenUrl),
                    gxInterfaceTokenUrl: encodeURIComponent(this.Gx.gxInterfaceTokenUrl),
                    gxInterfaceTokenEffectiveDuration: encodeURIComponent(this.Gx.gxInterfaceTokenEffectiveDuration),
                    gxGetUserByToken: encodeURIComponent(this.Gx.gxGetUserByToken),
                    gxGetUserByMemberId: encodeURIComponent(this.Gx.gxGetUserByMemberId),
                    gxGetCity: encodeURIComponent(this.Gx.gxGetCity),
                    gxGetProjectListByCity: encodeURIComponent(this.Gx.gxGetProjectListByCity),
                    gxPushMessageToApp: encodeURIComponent(this.Gx.gxPushMessageToApp),
                }
                convertAddCode(dataB.gxAppId, data => {
                    dataB.gxAppId = data;
                });
                setGx(dataB).then(() => {
                    done();
                    this.$message({
                        message: '提交成功',
                        type: 'success'
                    })
                    this.activeName = 'Gx'
                    this.getData()
                })
            },
            submitEsb(form, done) {
                let dataC = {
                    esbWebServicePrev: encodeURIComponent(this.Esb.esbWebServicePrev),
                    esbBasicUserName: encodeURIComponent(this.Esb.esbBasicUserName),
                    esbBasicPassword: encodeURIComponent(this.Esb.esbBasicPassword),
                    esbGiveMallSystemId: encodeURIComponent(this.Esb.esbGiveMallSystemId),
                    esbGiveBpmSystemId: encodeURIComponent(this.Esb.esbGiveBpmSystemId),
                    esbGiveIdmSystemId: encodeURIComponent(this.Esb.esbGiveIdmSystemId),
                    esbGivePytSystemId: encodeURIComponent(this.Esb.esbGivePytSystemId),
                }
                console.log(dataC)
                setEsb(dataC).then(() => {
                    done()
                    this.$message({
                        message: '提交成功',
                        type: 'success'
                    })
                    this.activeName = 'Esb'
                    this.getData()
                })
            },
            submitBpm(form, done) {
                let dataD = {
                    bpmInitiationProcessUrl: encodeURIComponent(this.Bpm.bpmInitiationProcessUrl),
                    bpmBsId: encodeURIComponent(this.Bpm.bpmBsId),
                    bpmBtId: encodeURIComponent(this.Bpm.bpmBtId),
                    bpmOrgAccount: encodeURIComponent(this.Bpm.bpmOrgAccount),
                    bpmOrgPassrwd: encodeURIComponent(this.Bpm.bpmOrgPassrwd),
                }
                setBpm(dataD).then(() => {
                    done()
                    this.$message({
                        message: '提交成功',
                        type: 'success'
                    })
                    this.activeName = 'Bpm'
                    this.getData()
                })
            },
        }
    };
</script>
